package com.example.androiduidemo2.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import com.example.androiduidemo2.CourseActivity;
import com.example.androiduidemo2.R;
import com.example.androiduidemo2.entity.Course;

import java.util.List;

public class CourseArrayAdapter extends ArrayAdapter<Course> {
    public CourseArrayAdapter(CourseActivity context, List<Course> courses) {
        super(context, 0, courses);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        Course course = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_course, parent, false);
        }
        TextView tvCourseName = convertView.findViewById(R.id.tvCourseName);
        TextView tvCourseId = convertView.findViewById(R.id.tvCourseId);
        TextView tvCourseTeacher = convertView.findViewById(R.id.tvCourseTeacher);
        TextView tvCourseClass = convertView.findViewById(R.id.tvCourseClass);
        TextView tvCourseTime = convertView.findViewById(R.id.tvCourseTime);

        // Populate the data into the template view using the data object
        tvCourseName.setText("课程名称：" + course.getCourseName());
        tvCourseId.setText("课程编号：" + course.getCourseId());
        tvCourseTeacher.setText("任课教师：" + course.getCourseTeacher());
        tvCourseClass.setText("学习班级：" + course.getCourseClass());
        tvCourseTime.setText(String.valueOf("课程学习：" + course.getCourseTime()));

        // Return the converted view to be inserted into the list
        return convertView;
    }
}